package com.gnerv.battle.boot.project.guard.service.impl;

import com.gnerv.battle.boot.project.guard.mapper.MonitorProjectMapper;
import com.gnerv.battle.boot.project.guard.model.bo.MonitorProjectBO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorProjectDTO;
import com.gnerv.battle.boot.project.guard.model.entity.MonitorProject;
import com.gnerv.battle.boot.project.guard.service.MonitorProjectService;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.gnerv.battle.boot.common.tools.PageTools.limitSize;
import static com.gnerv.battle.boot.common.tools.PageTools.limitStart;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class MonitorProjectServiceImpl implements MonitorProjectService {
    
    private final MonitorProjectMapper monitorProjectMapper;

    @Override
    public boolean create(@NonNull MonitorProjectBO monitorProjectBO) {
        MonitorProject monitorProject = monitorProjectBO.toCreateMonitorProject();
        monitorProjectMapper.insert(monitorProject);
        return true;
    }

    @Override
    public boolean deleteByUkId(@NonNull String ukId) {
        monitorProjectMapper.deleteByUkId(ukId);
        return true;
    }

    @Override
    public boolean updateByUkId(@NonNull MonitorProjectBO monitorProjectBO) {
        MonitorProject monitorProject = monitorProjectBO.toUpdateMonitorProject();
        monitorProjectMapper.updateByUkId(monitorProject);
        return true;
    }

    @Override
    public MonitorProjectDTO selectByUkId(@NonNull String ukId) {
        return monitorProjectMapper.selectByUkId(ukId);
    }

    @Override
    public List<MonitorProjectDTO> listByName(String name, Integer page, Integer size) {
        return monitorProjectMapper.listByName(name, limitStart(page, size), limitSize(size));
    }

    
}
